﻿var domainResource = 'http://localhost:821';

function getElem(ElemID, ElemType, Parent) {
    if (!document.getElementById(ElemID)) {
        var newNode = document.createElement(ElemType);
        newNode.setAttribute("id", ElemID);
        Parent.appendChild(newNode);
    }
    return document.getElementById(ElemID);
}
function getInt(pxNum) {
    if (!pxNum) return 0;
    return parseInt(pxNum.toString().replace("px", ""));
}

function showDivDialog(title,content,showClose,width,height)
{
    if(title==null) title="&nbsp;";
    if(content==null) content="&nbsp;";
    if(width==null) width=400;
    if(height==null) height=250;

    var backDiv=document.getElementById("backDiv");
    var alertDiv=document.getElementById("alertDiv");
    if(backDiv && alertDiv)
    {
        backDiv.style.display="";
        alertDiv.style.display="";
    }
    else
    {
        backDiv=getElem("backDiv","div",document.body);
        alertDiv=getElem("alertDiv","div",document.body);
    }

    backDiv.style.filter = "Alpha(Opacity=40)";  //ie
    backDiv.style.opacity = .4; //firefox
    backDiv.style.backgroundColor = "#fff";
    backDiv.style.zIndex=999999;
    backDiv.style.position="absolute";
    backDiv.style.left = "0px";
    backDiv.style.top = "0px";
    backDiv.style.width = document.documentElement.clientWidth + "px";
    backDiv.style.height = document.documentElement.scrollHeight + "px";
    //if(getInt(backDiv.style.height) < 768) backDiv.style.height = "768px";
    backDiv.style.textAlign="center";

    var str = "";
    if (title == "") {
        str = content;
    }
    else {
        str += '<table cellpadding="0" cellspacing="0" style="width:100%;" id="titleDiv">';
        str += '    <tr>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_t_l.gif);width:5px;height:30px;"></td>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_t_c.gif);"><div style="float:left;color:#ffffff;font-weight:bold;font-size:14px;padding:5px;">' + title + '</div><div style="float:right;">' + (showClose ? '<a id="btnClose" href="javascript:void(0);" onmousedown="closeDivDialog()"><img src="'+domainResource+'/Images/dialog/dia_close.gif" style="border:0px;" /></a>' : '') + '</div></td>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_t_r.gif);width:6px;height:30px;"></td>';
        str += '    </tr>';
        str += '</table>';
        str += '<table cellpadding="0" cellspacing="0" style="width:100%;">';
        str += '    <tr>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_m_l.gif);width:5px;"></td>';
        str += '        <td align="center" style="padding:8px 8px 8px 5px; background-color:#ffffff; height:' + (height - 52) + 'px;">';
        str += '        ' + content;
        str += '        </td>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_m_r.gif);width:6px;"></td>';
        str += '    </tr>';
        str += '    <tr>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_b_l.gif);width:5px;height:6px;"></td>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_b_c.gif);height:6px;"></td>';
        str += '        <td style="background:url('+domainResource+'/Images/dialog/dia_b_r.gif);width:6px;height:6px;"></td>';
        str += '    </tr>';
        str += '</table>';
    }
    
    alertDiv.innerHTML = str;
    alertDiv.style.zIndex=1000000;
    alertDiv.style.position = "absolute";
    alertDiv.style.width = width + "px";
    alertDiv.style.height = height + "px";
    alertDiv.style.left = ((getInt(backDiv.style.width) - getInt(alertDiv.style.width)) / 2) + "px";
    alertDiv.style.top = ((screen.availHeight - getInt(alertDiv.style.height)) / 2 + document.documentElement.scrollTop - 100) + "px";

    if (title != "") {
        var titleDiv = document.getElementById("titleDiv");
        titleDiv.onmousedown = function (evt) {
            curMoveObj = alertDiv;
            if (evt) { //firefox
                pX = evt.pageX - getInt(curMoveObj.style.left);
                pY = evt.pageY - getInt(curMoveObj.style.top);
            }
            else { //ie
                pX = event.x - curMoveObj.style.pixelLeft;
                pY = event.y - curMoveObj.style.pixelTop;
            }
        }
    }
}

function closeDivDialog()
{
    var backDiv = document.getElementById("backDiv");
    var alertDiv = document.getElementById("alertDiv");
    backDiv.style.display="none";
    alertDiv.style.display="none";
}


function showDivDialogWin(title,Url,width,height)
{
    var scontent = '<iframe id="ifrDialogMain" frameborder=0 scrolling="no" src="' + Url + '"  width="99%" height="99%"></iframe>';
    showDivDialog(title, scontent, true, width, height);
}
function showLoading()
{
    showDivDialog("", '<img src="'+domainResource+'/Images/loading.gif" alt="页面加载中.." />', false, 360, 220);
}